﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="codemonk"
    targetNamespace="codemonk.common.injection.objectbuilder.config.xsd"
    elementFormDefault="qualified"
    xmlns="codemonk.common.injection.objectbuilder.config.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="codemonk">
    <xs:complexType>
      <xs:sequence>
        <!--常量，所有的常量在初始化都会在系统中缓存，直到系统关闭或配置文件发生更改才会被释放，不建议常量区放置太多的值-->
        <xs:element name="constants"  minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="constant"  minOccurs="0" maxOccurs="1024" type="object"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!--常量会在初始化之后，有CLR管理释放与否-->
        <xs:element name="variables"  minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="variable"  type="object" minOccurs="0" maxOccurs="1024"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>



  <xs:complexType name="object">
    <xs:sequence>
      <xs:element name="name"  type="xs:string"  maxOccurs="1" minOccurs="1" />
      <xs:element name="description" type="xs:string"  maxOccurs="1" minOccurs="0" />
      <xs:element name="value" type="valuedescription" maxOccurs="1" minOccurs="1" />
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="valuedescription">
    <xs:choice>
      <xs:element name="simplevalue"  maxOccurs="1" >
        <xs:complexType>
          <xs:attribute name="value" type="xs:string"/>
          <xs:attribute name="type" type="simplevaluetype"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="complexvalue" maxOccurs="1" >
        <xs:complexType>
          <xs:sequence>
            <xs:element name="classpath" type="xs:string" maxOccurs="1" minOccurs="1" />
            <xs:element name="injections" maxOccurs="1" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <!--构造函数注入，两种参数，简单的，可以直接写参数列表argments，复杂的需要使用parameters，按照参数的顺序逐个填写参数-->
                  <xs:element name="ctor"   maxOccurs="1" minOccurs="0" >
                    <xs:complexType>
                      <xs:choice>
                        <xs:element name="parameters" type="parameters"   />
                      </xs:choice>
                    </xs:complexType>
                  </xs:element>
                  <!--属性注入，需要填写具体需要注入的属性名称以及属性值-->
                  <xs:element name="properties" type="properties" maxOccurs="1" minOccurs="0"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>
  <xs:simpleType name="simplevaluetype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="sbyte"/>
      <xs:enumeration value="byte"/>
      <xs:enumeration value="short"/>
      <xs:enumeration value="ushort"/>
      <xs:enumeration value="int"/>
      <xs:enumeration value="uint"/>
      <xs:enumeration value="long"/>
      <xs:enumeration value="ulong"/>
      <xs:enumeration value="char"/>
      <xs:enumeration value="float"/>
      <xs:enumeration value="double"/>
      <xs:enumeration value="bool "/>
      <xs:enumeration value="string"/>
      <xs:enumeration value="ipaddress"/>
      <xs:enumeration value="ipendpoint"/>
      <xs:enumeration value="object"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="properties">
    <xs:sequence >
      <xs:element name="property" maxOccurs="32" minOccurs="0">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string"  use="required"/>
          <xs:attribute name="value" type="xs:string"/>
          <xs:attribute name="type" type="simplevaluetype"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="parameters">
    <xs:sequence>
      <xs:element name="parameter" minOccurs="0" maxOccurs="128">
        <xs:complexType >
          <xs:attribute name="value" type="xs:string"/>
          <xs:attribute name="type" type="simplevaluetype"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
